{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3c07757e",
   "metadata": {},
   "source": [
    "# 实践1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "7b307c75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的余额10\n",
      "------商品信息------\n",
      "商品编号: 0 ,商品名称: 珍珠奶茶小杯 ,商品价格: 6\n",
      "商品编号: 1 ,商品名称: 椰果奶茶小杯 ,商品价格: 7\n",
      "商品编号: 2 ,商品名称: 芝士奶盖大杯 ,商品价格: 8\n",
      "商品编号: 3 ,商品名称: 芋圆波波奶茶 ,商品价格: 15\n",
      "商品编号: 4 ,商品名称: 杨枝甘露 ,商品价格: 8\n"
     ]
    }
   ],
   "source": [
    "#信息储存模块\n",
    "Alipay = input(\"请输入你的余额\")\n",
    "goods_list = [['珍珠奶茶小杯',6],\n",
    "              ['椰果奶茶小杯',7],\n",
    "              ['芝士奶盖大杯',8],\n",
    "              ['芋圆波波奶茶',15],\n",
    "              ['杨枝甘露',8],\n",
    "             ]\n",
    "\n",
    "print('------商品信息------')\n",
    "print(\"商品编号:\",0,\",商品名称:\",goods_list[0][0],\",商品价格:\",goods_list[0][1])\n",
    "print(\"商品编号:\",1,\",商品名称:\",goods_list[1][0],\",商品价格:\",goods_list[1][1])\n",
    "print(\"商品编号:\",2,\",商品名称:\",goods_list[2][0],\",商品价格:\",goods_list[2][1])\n",
    "print(\"商品编号:\",3,\",商品名称:\",goods_list[3][0],\",商品价格:\",goods_list[3][1])                 \n",
    "print(\"商品编号:\",4,\",商品名称:\",goods_list[4][0],\",商品价格:\",goods_list[4][1])             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "85c89e66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的余额100\n",
      "请输入你想购买的商品编号(输入'q'退出购买)4\n",
      "8\n",
      "感谢您的购买，您的余额剩余: 92\n",
      "请输入你想购买的商品编号(输入'q'退出购买)4\n",
      "8\n",
      "感谢您的购买，您的余额剩余: 84\n",
      "请输入你想购买的商品编号(输入'q'退出购买)4\n",
      "8\n",
      "感谢您的购买，您的余额剩余: 76\n",
      "请输入你想购买的商品编号(输入'q'退出购买)4\n",
      "8\n",
      "感谢您的购买，您的余额剩余: 68\n",
      "请输入你想购买的商品编号(输入'q'退出购买)3\n",
      "15\n",
      "感谢您的购买，您的余额剩余: 53\n",
      "请输入你想购买的商品编号(输入'q'退出购买)3\n",
      "15\n",
      "感谢您的购买，您的余额剩余: 38\n",
      "请输入你想购买的商品编号(输入'q'退出购买)3\n",
      "15\n",
      "感谢您的购买，您的余额剩余: 23\n",
      "请输入你想购买的商品编号(输入'q'退出购买)3\n",
      "15\n",
      "感谢您的购买，您的余额剩余: 8\n",
      "请输入你想购买的商品编号(输入'q'退出购买)3\n",
      "15\n",
      "您的余额不足,剩余： 8\n"
     ]
    }
   ],
   "source": [
    "#购买模块\n",
    "Alipay = input(\"请输入您的余额\")\n",
    "while True:\n",
    "    buy = input(\"请输入你想购买的商品编号(输入'q'退出购买)\")\n",
    "    if buy.isdigit():\n",
    "        if buy == \"q\":\n",
    "            break\n",
    "        elif int(buy) > 5:\n",
    "            print(\"超出商品列表\")\n",
    "        else:\n",
    "            Alipay_new = Alipay\n",
    "            value = goods_list[int(buy)][1]\n",
    "            print(value)\n",
    "            if int(Alipay) >= value:\n",
    "                Alipay_new = int(Alipay) - value\n",
    "                print(\"感谢您的购买，您的余额剩余:\",Alipay_new)\n",
    "                Alipay = Alipay_new\n",
    "            else:\n",
    "                print(\"您的余额不足,剩余：\",Alipay_new)\n",
    "                break\n",
    "    else:\n",
    "        print(\"你故意找茬是吧？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "9dce11e9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的余额10\n",
      "请输入你想购买的商品编号(输入'q'退出购买)sdfsedfsdf\n",
      "你故意找茬是吧？\n",
      "请输入你想购买的商品编号(输入'q'退出购买)10\n",
      "超出商品列表\n",
      "请输入你想购买的商品编号(输入'q'退出购买)1\n",
      "7\n",
      "感谢您的购买，您的余额剩余: 3\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-101-b1d5e9ee3c5c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mAlipay\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入您的余额\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m     \u001b[0mbuy\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你想购买的商品编号(输入'q'退出购买)\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mbuy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0misdigit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mbuy\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"q\"\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mE:\\Anaconda\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m    858\u001b[0m                 \u001b[1;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    859\u001b[0m             )\n\u001b[1;32m--> 860\u001b[1;33m         return self._input_request(str(prompt),\n\u001b[0m\u001b[0;32m    861\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    862\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mE:\\Anaconda\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m    902\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    903\u001b[0m                 \u001b[1;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 904\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Interrupted by user\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    905\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    906\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid Message:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "#运行测试模块，用于测试代码是否能正常运行后用于购买模块\n",
    "Alipay = input(\"请输入您的余额\")\n",
    "while True:\n",
    "    buy = input(\"请输入你想购买的商品编号(输入'q'退出购买)\")\n",
    "    if buy.isdigit():\n",
    "        if buy == \"q\":\n",
    "            break\n",
    "        elif int(buy) > 5:\n",
    "            print(\"超出商品列表\")\n",
    "        else:\n",
    "            Alipay_new = Alipay\n",
    "            value = goods_list[int(buy)][1]\n",
    "            print(value)\n",
    "            if int(Alipay) >= value:\n",
    "                Alipay_new = int(Alipay) - value\n",
    "                print(\"感谢您的购买，您的余额剩余:\",Alipay_new)\n",
    "                Alipay = Alipay_new\n",
    "            else:\n",
    "                print(\"您的余额不足,剩余：\",Alipay_new)\n",
    "                break\n",
    "    else:\n",
    "        print(\"你故意找茬是吧？\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "112139fc",
   "metadata": {},
   "source": [
    "# 实践2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "260c7d97",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:········\n",
      "guess_digit:55\n",
      "yes, you got it.\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0\n",
    "\n",
    "if hide_card <100 and hide_card >0:\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit = int(input(\"guess_digit:\"))\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes, you got it.\")\n",
    "                break\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"think smaller...\")\n",
    "            else:\n",
    "                print(\"think bigger...\")\n",
    "            count +=1\n",
    "        else:\n",
    "            print(\"猜这么多次都不对,你个笨蛋!\")\n",
    "            print(\"正确答案：%s\"%(hide_card))\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入数字在0-99之间。不要耍赖！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d5a0429",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
